package com.example.lsxz;


import cn.hutool.setting.dialect.Props;
import okhttp3.*;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@EnableScheduling
public class lsxz {

    @Scheduled(cron = "0 0 8 * * ?")
    public void lsxzDk() throws IOException {
        //读取用户token
        Props props = new Props("login.properties");
        String token = props.getProperty("token");
        //拼接成请求的token。注意“JWT后面有逗号”
        String authorization="JWT "+token;

        //晨报打卡
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        RequestBody body = RequestBody.create(mediaType, "{\n" +
                "\t\"value\": \"36.2\",\n" +
                "\t\"condition\": \"A\",\n" +
                "\t\"home_condition\": \"A\",\n" +
                "\t\"watched\": false,\n" +
                "\t\"watched_location\": \"\",\n" +
                "\t\"stayed\": false,\n" +
                "\t\"stayed_contacted\": false,\n" +
                "\t\"family_conditions\": \"\",\n" +
                "\t\"is_contacted\": false,\n" +
                "\t\"contacted_health\": \"\",\n" +
                "\t\"personid\": \"\",\n" +
                "\t\"notes\": \"\",\n" +
                "\t\"location\": {\n" +
                "\t\t\"status\": 0,\n" +
                "\t\t\"lat\": 36.0482,\n" +
                "\t\t\"lng\": 115.436246,\n" +
                "\t\t\"nation\": \"中国\",\n" +
                "\t\t\"nation_code\": \"156\",\n" +
                "\t\t\"address\": \"河南省濮阳市南乐县003县道\",\n" +
                "\t\t\"famous\": \"\",\n" +
                "\t\t\"recommend\": \"南乐县千口镇西节村\",\n" +
                "\t\t\"district_code\": \"410923\",\n" +
                "\t\t\"district_name\": \"南乐县\",\n" +
                "\t\t\"district_lat\": 36,\n" +
                "\t\t\"district_lng\": 115.410072,\n" +
                "\t\t\"town_code\": \"410923202\",\n" +
                "\t\t\"town_name\": \"千口镇\",\n" +
                "\t\t\"town_lat\": 36.094574,\n" +
                "\t\t\"town_lng\": 115.413864\n" +
                "\t}\n" +
                "}");
        Request request = new Request.Builder()
                .url("https://apii.lynu.edu.cn/v1/temperatures/")
                .method("POST", body)
                .addHeader("charset", "utf-8")
                .addHeader("Accept-Encoding", "gzip")
                .addHeader("accept", "application/json")
                .addHeader("referer", "https://servicewechat.com/wx626b4a9845fb263a/13/page-frame.html")
                .addHeader("authorization", authorization)
                .addHeader("content-type", "application/json; charset=utf-8")
                .addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; OPPO R11 Plus Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 MicroMessenger/7.0.12.1620(0x27000C34) Process/appbrand2 NetType/WIFI Language/zh_CN ABI/arm32")
                .addHeader("Content-Length", "646")
                .addHeader("Host", "apii.lynu.edu.cn")
                .addHeader("Connection", "Keep-Alive")
                .build();
        Response response = client.newCall(request).execute();
        System.out.println(response.toString());



        //午报打卡
        OkHttpClient client2= new OkHttpClient().newBuilder().build();
        MediaType mediaType2 = MediaType.parse("application/json; charset=utf-8");
        RequestBody body2 = RequestBody.create(mediaType2, "{\"value\":\"36.2\",\"condition\":\"A\"}");
        Request request2 = new Request.Builder()
                .url("https://apii.lynu.edu.cn/v1/noons/")
                .method("POST", body2)
                .addHeader("charset", "utf-8")
                .addHeader("Accept-Encoding", "gzip")
                .addHeader("accept", "application/json")
                .addHeader("referer", "https://servicewechat.com/wx626b4a9845fb263a/13/page-frame.html")
                .addHeader("authorization", authorization)
                .addHeader("content-type", "application/json; charset=utf-8")
                .addHeader("User-Agent", "Mozilla/5.0 (Linux; Android 5.1.1; OPPO R11 Plus Build/NMF26X; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/74.0.3729.136 Mobile Safari/537.36 MicroMessenger/7.0.12.1620(0x27000C34) Process/appbrand2 NetType/WIFI Language/zh_CN ABI/arm32")
                .addHeader("Content-Length", "646")
                .addHeader("Host", "apii.lynu.edu.cn")
                .addHeader("Connection", "Keep-Alive")
                .build();
        Response response2 = client2.newCall(request2).execute();
        System.out.println(response2.toString());
    }
}
